public class Parser extends Object
Modifier and Type | Field and Description |
---|---|
private File |
_file
Input file.
|
private FileReader |
_fr
Input file.
|
private IParserHandler |
_handler
Handler which receives events from the parser.
|
private Stack<ElementStart> |
_openElements
Stack containing all opened and still non-closed elements.
|
private BufferedReader |
_reader
Input file.
|
Constructor and Description |
---|
Parser() |
Modifier and Type | Method and Description |
---|---|
private void |
checkValidity(ElementEnd element)
Checks whether the document is well-formed.
|
private void |
destroy()
Closes the input input file specified in the
parse() method. |
private void |
doParsing()
Reads the input file char by char.
|
private void |
init()
Opens the input file specified in the
parse() method. |
void |
parse(File inputFile,
IParserHandler handler)
Parses the HTML file and converts it using the particular handler.
|
private MyElement |
parseElement(String elementString)
Parses element.
|
private void |
readContent(char firstChar)
Reads text content of an element.
|
private void |
readElement()
Reads elements (tags).
|
private File _file
private FileReader _fr
private BufferedReader _reader
private IParserHandler _handler
private Stack<ElementStart> _openElements
public void parse(File inputFile, IParserHandler handler) throws FatalErrorException
<p
)</p>
)inputFile
- input HTML filehandler
- receives events such as startElement (ie. <html)
>
, endElement, ...FatalErrorException
- fatal error (ie. input file can't be opened) occursprivate void init() throws FatalErrorException
parse()
method.FatalErrorException
- when input file can't be openedprivate void destroy() throws FatalErrorException
parse()
method.FatalErrorException
- when input file can't be closedprivate void doParsing() throws IOException
"<"
char is reached readElement()
is called otherwise readContent()
is called.IOException
- when input error occursprivate void readElement() throws IOException
comment
, startElement
and
endElement
events to the handler.IOException
- when input error occursprivate MyElement parseElement(String elementString)
ElementStart
object
if it's a start element.elementString
- string containing the element with its
attributes (but without leading "<" and ending
">")ElementStart
or ElementEnd
object.private void readContent(char firstChar) throws IOException
character
event to the handler.firstChar
- first char read in doParsing()
methodIOException
- when input error occursprivate void checkValidity(ElementEnd element)
endElement
events for the elements which
were opened but not correctly closed.element
- the latest ending element which was reached